cordova.define("com.wingsfrog.socket.wfSocket", function(require, exports, module) { var exec = require('cordova/exec');


var wfSocket = {
    listenOnPort:function(successCallback, errorCallback, args) {
        exec(successCallback, errorCallback, "wfSocket", "listenOnPort", args);
    },
    connect:function(successCallback, errorCallback, args) {
        exec(successCallback, errorCallback, "wfSocket", "connect", args);
    },
    close:function(successCallback, errorCallback, args) {
        exec(successCallback, errorCallback, "wfSocket", "close", args);
    },
    smartConnect:function(successCallback, errorCallback, args) {
        exec(successCallback, errorCallback, "wfSocket", "smartConnect", args);
    },
    searchPi:function(successCallback, errorCallback, args) {
        exec(successCallback, errorCallback, "wfSocket", "getPiList", args);
    },
    connectPi:function(successCallback, errorCallback, args) {
        exec(successCallback, errorCallback, "wfSocket", "connectPi", args);
    },
    connectServer:function(successCallback, errorCallback, args) {
        exec(successCallback, errorCallback, "wfSocket", "connectServer", args);
    },
    sendData:function(successCallback, errorCallback, args) {
        exec(successCallback, errorCallback, "wfSocket", "sendData", args);
    },
    receiveHookName : 'SOCKET_RECEIVE_DATA_HOOK',
    receiveMsg : function (host, port, connectionId, chunk) {
        'use strict';
        var evReceive = document.createEvent('Events');

        evReceive.initEvent(wfSocket.receiveHookName, true, true);
        evReceive.metadata = {
            connection: {
                id: connectionId,
                host: host,
                port: port,
            },
            data: chunk.split('|')
        };
        document.dispatchEvent(evReceive);
    }
};

module.exports =wfSocket;

});
